using System;
using System.Collections;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
namespace Microsoft.Phone.Controls
{
	internal static class PhoneHelper
	{
		public const double SipLandscapeHeight = 259.0;
		public const double SipPortraitHeight = 339.0;
		public const double SipTextCompletionHeight = 62.0;
		public static bool TryGetPhoneApplicationFrame(out PhoneApplicationFrame phoneApplicationFrame)
		{
			phoneApplicationFrame = (Application.get_Current().get_RootVisual() as PhoneApplicationFrame);
			return phoneApplicationFrame != null;
		}
		public static bool IsPortrait(this PhoneApplicationFrame phoneApplicationFrame)
		{
			return (13 & phoneApplicationFrame.get_Orientation()) == phoneApplicationFrame.get_Orientation();
		}
		public static double GetUsefulWidth(this PhoneApplicationFrame phoneApplicationFrame)
		{
			if (!phoneApplicationFrame.IsPortrait())
			{
				return phoneApplicationFrame.get_ActualHeight();
			}
			return phoneApplicationFrame.get_ActualWidth();
		}
		public static double GetUsefulHeight(this PhoneApplicationFrame phoneApplicationFrame)
		{
			if (!phoneApplicationFrame.IsPortrait())
			{
				return phoneApplicationFrame.get_ActualWidth();
			}
			return phoneApplicationFrame.get_ActualHeight();
		}
		public static Size GetUsefulSize(this PhoneApplicationFrame phoneApplicationFrame)
		{
			return new Size(phoneApplicationFrame.GetUsefulWidth(), phoneApplicationFrame.GetUsefulHeight());
		}
		private static bool TryGetFocusedTextBox(out TextBox textBox)
		{
			textBox = (FocusManager.GetFocusedElement() as TextBox);
			return textBox != null;
		}
		public static bool IsSipShown()
		{
			TextBox textBox;
			return PhoneHelper.TryGetFocusedTextBox(out textBox);
		}
		public static bool IsSipTextCompletionShown(this TextBox textBox)
		{
			if (textBox.get_InputScope() == null)
			{
				return false;
			}
			IList names = textBox.get_InputScope().get_Names();
			IEnumerator enumerator = names.GetEnumerator();
			try
			{
				while (enumerator.MoveNext())
				{
					InputScopeName inputScopeName = (InputScopeName)enumerator.get_Current();
					switch (inputScopeName.get_NameValue())
					{
					case 49:
					case 50:
						return true;
					}
				}
			}
			finally
			{
				IDisposable disposable = enumerator as IDisposable;
				if (disposable != null)
				{
					disposable.Dispose();
				}
			}
			return false;
		}
		public static Size GetSipCoveredSize(this PhoneApplicationFrame phoneApplicationFrame)
		{
			if (!PhoneHelper.IsSipShown())
			{
				return new Size(0.0, 0.0);
			}
			double usefulWidth = phoneApplicationFrame.GetUsefulWidth();
			double num = phoneApplicationFrame.IsPortrait() ? 339.0 : 259.0;
			TextBox textBox;
			if (PhoneHelper.TryGetFocusedTextBox(out textBox) && textBox.IsSipTextCompletionShown())
			{
				num += 62.0;
			}
			return new Size(usefulWidth, num);
		}
		public static Size GetSipUncoveredSize(this PhoneApplicationFrame phoneApplicationFrame)
		{
			double usefulWidth = phoneApplicationFrame.GetUsefulWidth();
			double num = phoneApplicationFrame.GetUsefulHeight() - phoneApplicationFrame.GetSipCoveredSize().get_Height();
			return new Size(usefulWidth, num);
		}
	}
}
